package com.avic.rong.activity.product;

import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.avic.rong.BaseActivity;
import com.avic.rong.R;
import com.avic.rong.activity.login.LoginPhoneActivity;
import com.avic.rong.bean.DeviceBean;
import com.avic.rong.course.activity.otherActivity.PeiXunBaoMingActivity;
import com.avic.rong.goodsSort.CarView;
import com.avic.rong.questionOrAnswer.DialogShare;
import com.avic.rong.questionOrAnswer.ShareUtilCallBack;
import com.avic.rong.shoppingCar.activity.ShoppingCarActivity;
import com.avic.rong.userOrder.activity.OrderConfirmActivity;
import com.avic.rong.utils.ConstantsUtils;
import com.avic.rong.utils.DateUtils;
import com.avic.rong.utils.DensityUtils;
import com.avic.rong.utils.DeviceUtils;
import com.avic.rong.utils.NetResponseListener;
import com.avic.rong.utils.SharedPreferencesUtil;
import com.avic.rong.utils.SmartHttp;
import com.avic.rong.utils.ToastTools;
import com.avic.rong.wedgit.NXHooldeView;
import com.avic.rong.wedgit.ScrollWebView;
import com.example.minato.minastore.utils.AppUtils;
import com.example.minato.minastore.utils.CircleProgressDialog;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.microquation.linkedme.android.callback.LMLinkCreateListener;
import com.microquation.linkedme.android.indexing.LMUniversalObject;
import com.microquation.linkedme.android.referral.LMError;
import com.microquation.linkedme.android.util.LinkProperties;
import com.orhanobut.logger.Logger;

import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import wendu.dsbridge.CompletionHandler;
import wendu.dsbridge.OnReturnValue;

public class DetailProductActivity extends BaseActivity implements ScrollWebView.OnScrollChangeListener, ShareUtilCallBack {


    public static final String ARG_SKUID = "skuId";
    public static final String TYPE = "type";
    public static final Integer AnimationDuration = 1;
    public static final String TYPE_ADDCARTFLAG = "addCartFlag";


    private String skuIdStr = "";

    @BindView(R.id.webview)
    ScrollWebView webView;

    @BindView(R.id.img_underline)
    ImageView img_underline;

    @BindView(R.id.shangpin)
    TextView shangpin;
    @BindView(R.id.pingjia)
    TextView pingjia;
    @BindView(R.id.xiangqing)
    TextView xiangqing;
    @BindView(R.id.tuijian)
    TextView tuijian;
    @BindView(R.id.img_back)
    ImageView img_back;
    @BindView(R.id.tv_share)
    ImageView tv_share;
    @BindView(R.id.tv_ok)
    ImageView tv_ok;
    @BindView(R.id.progress_bar)
    ProgressBar progress_bar;

    @BindView(R.id.rl_root_bottom)
    RelativeLayout rl_root_bottom;


    @BindView(R.id.rl_root)
    RelativeLayout rl_top;//顶部

    private DialogShare dialogShare;
    private CarView carView;
    private TextView car_number;//购物车数量


    private float startX = 0f;
    private boolean ishade = true;


    private boolean isClickTab = false;

    private String urlString;
    private boolean addCartFlag = false;
    private CircleProgressDialog circleProgressDialog;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_detail_product;
    }

    @Override
    protected void initView() {

        startX = shangpin.getX();
        skuIdStr = getIntent().getStringExtra(ARG_SKUID);
        webView.addJavascriptObject(this, null);
        webView.setListener(this);
//        skuIdStr = "448";
        urlString = AppUtils.BASE_URL + "appGood/" + skuIdStr;
//        webView.loadUrl(url);

//
//        webView.setWebViewClient(new MyWebViewClient(webView));
        webView.setHorizontalScrollBarEnabled(false);
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setSupportZoom(false);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setDisplayZoomControls(false);
        webView.setWebChromeClient(new MyWebChromeClient());


//        webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
//        webView.getSettings().setJavaScriptEnabled(true);
//        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);//适应内容大小

//        webView.loadUrl("http://10.2.91.17:8021/appGood/207556");
//        webView.loadUrl("http://nm.rongrong.huazhi365.com/appGood/207556");
        webView.loadUrl(urlString);

        webView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                return true;
            }
        });

        rl_top.setAlpha(0f);

        carView = new CarView(this);
        car_number = carView.findViewById(R.id.car_number);
        carView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(DetailProductActivity.this, ShoppingCarActivity.class);
                startActivity(intent);
            }
        });
        carView.show();


        getCartNum();

        circleProgressDialog = new CircleProgressDialog(context);
        circleProgressDialog.show();

    }


    private class MyWebChromeClient extends WebChromeClient {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            Logger.i("-------------------------newProgress:" + newProgress);
            progress_bar.setProgress(newProgress);
            if (newProgress == 100) {
                progress_bar.setVisibility(View.GONE);
                circleProgressDialog.dismiss();
            }
            super.onProgressChanged(view, newProgress);
        }

        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);

        }

    }

    /**
     * 获取购物车数量
     */
    private void getCartNum() {

        String tokenStr = ConstantsUtils.EMPTY_STR;
        try {
            tokenStr = URLEncoder.encode(SharedPreferencesUtil.getLoginToken(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String urlStr = AppUtils.BASE_URL + "cart/getCartNum?token=" + tokenStr + "&deviceId=" + DeviceUtils.getIMEString(context);
        SmartHttp.getHttp(urlStr, new NetResponseListener() {
            @Override
            public void sucListener(JSONObject response) {
                if (ConstantsUtils.STATUS_SUCCESS_0000.equals(response.optString("code"))) {
                    car_number.setText(response.optString("data"));
                }
            }

            @Override
            public void errListener(String error_msg) {

            }
        });
    }


    private void addProductionAnimationDetail(View addView, CarView numberView) {
        NXHooldeView nxHooldeView = new NXHooldeView(this);
        nxHooldeView.setControlPointPositionUp(false);
        int position[] = new int[2];
//        addView.getLocationInWindow(position);
        int width = DensityUtils.getWindowWidth2(context);
        int height = DensityUtils.getWindowHeight2(context);
        position[0] = width / 2;
        position[1] = height;

        nxHooldeView.setStartPosition(new Point(position[0], position[1]));
        ViewGroup rootView = (ViewGroup) this.getWindow().getDecorView();
        rootView.addView(nxHooldeView);
        int endPosition[] = numberView.getLocation();
//        numberView.getLocationInWindow(endPosition);
        nxHooldeView.setEndPosition(new Point(endPosition[0] + numberView.getWidth() / 2 - NXHooldeView.VIEW_SIZE / 2, endPosition[1]));
        nxHooldeView.startBeizerAnimation();
    }


    //同步获取编码token
    @JavascriptInterface
    public String getLoginUserEncode(Object msg) {
        String login_token = "";
        if (SharedPreferencesUtil.isLogin()) {
            try {
                login_token = URLEncoder.encode(SharedPreferencesUtil.getLoginToken(), "UTF-8");
            } catch (Exception e) {
                Logger.i(e.getMessage());
            }
        }
        return login_token;
    }

    //同步获取token
    @JavascriptInterface
    public String getLoginUser(Object msg) {
        String login_token = "";
        if (SharedPreferencesUtil.isLogin()) {
            login_token = SharedPreferencesUtil.getLoginToken();
        }
        return login_token;
    }


    //异步获取token
    @JavascriptInterface
    public void getLoginUserAsyn(Object msg, CompletionHandler<String> handler) {
        String login_token = "";
        if (!SharedPreferencesUtil.isLogin()) {
            Intent intent = new Intent(DetailProductActivity.this, LoginPhoneActivity.class);
            intent.putExtra("come_from", "DetailProductActivity");
            startActivity(intent);
        } else {
            login_token = SharedPreferencesUtil.getLoginToken();
        }
        Logger.i("----" + login_token);
        handler.complete(login_token);
    }

    //加入购物车
    @JavascriptInterface
    public void postCartDataAsyn(Object msg, CompletionHandler<String> handler) {

        JsonParser parser = new JsonParser();
        JsonElement element = parser.parse((String) msg);
        if (element.isJsonObject()) {
            JsonObject jsonElement = (JsonObject) element;
            JsonObject skuStrObject = jsonElement.get("skuStr").getAsJsonObject();
            String orderType = jsonElement.get("orderType").getAsString();

            Map<String, String> map = new HashMap<>();
//          String skuStr = "{" + "\"" + skuId + "\"" + ":" + "1}";
            map.put("skuStr", skuStrObject.toString());
            map.put("orderType", orderType);
            map.put("buyAgain", "0");        //是否再次购买（0/1）
            map.put("token", SharedPreferencesUtil.getLoginToken());
            map.put("deviceId", DeviceUtils.getIMEString(context));
            Logger.i("----22-------" + SharedPreferencesUtil.getLoginToken() + "------diviceId:" + DeviceUtils.getIMEString(context));
            SmartHttp.postHttpForm(AppUtils.BASE_URL + "cart/addCart", map, new NetResponseListener() {
                @Override
                public void sucListener(JSONObject response) {
                    if (ConstantsUtils.STATUS_SUCCESS_0000.equals(response.optString("code"))) {
                        car_number.setText(response.optString("data"));
                        Logger.i("----22-------" + response.optString("data") + "------diviceId:" + DeviceUtils.getIMEString(context));

                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                addCartFlag = true;
                                addProductionAnimationDetail(carView, carView);

                            }
                        });
                    } else {
                        ToastTools.showToast("添加购物车失败");
                    }
                }

                @Override
                public void errListener(String error_msg) {

                }
            });
        }


        DeviceBean deviceBean = new DeviceBean(SharedPreferencesUtil.getLoginToken(), DeviceUtils.getIMEString(DetailProductActivity.this));
        handler.complete(new Gson().toJson(deviceBean));

    }


    //立即购买
    @JavascriptInterface
    public void imediateBuyAsyn(Object msg, CompletionHandler<String> handler) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
//                Toast toast = Toast.makeText(DetailProductActivity.this, msg + "", Toast.LENGTH_SHORT);
//                toast.setGravity(Gravity.CENTER, 0, 0);
//                toast.show();
                if (SharedPreferencesUtil.isLogin()) {
                    JsonParser parser = new JsonParser();
                    JsonElement element = parser.parse((String) msg);
                    if (element.isJsonObject()) {
                        JsonObject jsonElement = (JsonObject) element;
                        JsonObject skuStr = jsonElement.get("skuStr").getAsJsonObject();
                        String orderType = jsonElement.get("orderType").getAsString();
                        Intent intent = new Intent(DetailProductActivity.this, OrderConfirmActivity.class);
                        intent.putExtra("skuStr", skuStr.toString());
                        intent.putExtra("orderType", orderType);
                        intent.putExtra("enterType", 2 + "");
                        startActivity(intent);
                    }
                } else {
                    Intent intent = new Intent(DetailProductActivity.this, LoginPhoneActivity.class);
                    intent.putExtra("come_from", "DetailProductActivity");
                    startActivity(intent);
                }
                DeviceBean deviceBean = new DeviceBean(SharedPreferencesUtil.getLoginToken(), DeviceUtils.getIMEString(DetailProductActivity.this));
                handler.complete(new Gson().toJson(deviceBean));
            }
        });

    }

    //在线阅读
    @JavascriptInterface
    public void onlineReaderAsyn(Object msg, CompletionHandler<String> handler) {
//        Toast toast = Toast.makeText(DetailProductActivity.this, msg + "", Toast.LENGTH_SHORT);
//        toast.setGravity(Gravity.CENTER, 0, 0);
//        toast.show();
        if (!SharedPreferencesUtil.isLogin()) {
            Intent intent = new Intent(DetailProductActivity.this, LoginPhoneActivity.class);
            intent.putExtra("come_from", "DetailProductActivity");
            startActivity(intent);
        }

        String keyword = (String) msg;


        String url = null;
        try {
            url = AppUtils.BASE_URL + "member/checkMemberService?token=" + URLEncoder.encode(SharedPreferencesUtil.getLoginToken(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        SmartHttp.getHttp(url, new NetResponseListener() {
            @Override
            public void sucListener(JSONObject response) {
                Logger.i("--------" + response.toString());
                String code = response.optString("code");
                if (ConstantsUtils.STATUS_REQUEST_ERROR_1001.equals(code)) {//开通会员
                    startActivity(DetailProductActivity.getIntent(DetailProductActivity.this, "288498"));
                } else if (ConstantsUtils.STATUS_SUCCESS_0000.equals(code)) {//已开通会员
                    startActivity(PDFReaderActivity.getIntent(DetailProductActivity.this, keyword));
                }
            }

            @Override
            public void errListener(String error_msg) {

            }
        });


        handler.complete("usertoken");
    }


    //客服
    @JavascriptInterface
    public void cserviceAsyn(Object msg, CompletionHandler<String> handler) {

//        Toast toast = Toast.makeText(DetailProductActivity.this, msg + "", Toast.LENGTH_SHORT);
//            toast.setGravity(Gravity.CENTER, 0, 0);
//            toast.show();
        if (SharedPreferencesUtil.isLogin()) {
            startActivity(OnlineCServiceActivity.getIntent(this, SharedPreferencesUtil.getLoginToken()));
        } else {
            Intent intent = new Intent(DetailProductActivity.this, LoginPhoneActivity.class);
            intent.putExtra("come_from", "DetailProductActivity");
            startActivity(intent);
        }


        handler.complete(msg + " [ asyn call]");
    }

    //去开通会员
    @JavascriptInterface
    public void goKaitongAsyn(Object msg, CompletionHandler<String> handler) {

//        Toast toast = Toast.makeText(DetailProductActivity.this, msg + "", Toast.LENGTH_SHORT);
//        toast.setGravity(Gravity.CENTER, 0, 0);
//        toast.show();
        startActivity(DetailProductActivity.getIntent(DetailProductActivity.this, "288498"));

        handler.complete(msg + " [ asyn call]");
    }


    //评论查看全部
    @JavascriptInterface
    public void commentAllAsyn(Object msg, CompletionHandler<String> handler) {
//        Toast toast = Toast.makeText(DetailProductActivity.this, msg + "", Toast.LENGTH_SHORT);
//        toast.setGravity(Gravity.CENTER, 0, 0);
//        toast.show();
        JsonParser parser = new JsonParser();
        JsonElement element = parser.parse((String) msg);
        if (element.isJsonObject()) {
            JsonObject jsonElement = (JsonObject) element;
            Integer idValue = jsonElement.get("idValue").getAsInt();
            Integer commentType = jsonElement.get("commentType").getAsInt();
//            Log.e("===sku",skuStr);
            startActivity(CommentListActivity.getIntent(DetailProductActivity.this, commentType, idValue));
        }


        handler.complete(msg + " [ asyn call]");
    }


    //查看
    @JavascriptInterface
    public void previewGoodDetailAsyn(Object msg, CompletionHandler<String> handler) {
//        Toast toast = Toast.makeText(DetailProductActivity.this, msg + "", Toast.LENGTH_SHORT);
//        toast.setGravity(Gravity.CENTER, 0, 0);
//        toast.show();
        String skuId = "";
        if (msg instanceof Integer) {
            skuId = String.valueOf(msg);
        } else if (msg instanceof String) {
            skuId = (String) msg;
        }
        startActivity(DetailProductActivity.getIntent(DetailProductActivity.this, skuId));

//        finish();
        handler.complete(msg + " [ asyn call]");
    }


    //收藏结果
    @JavascriptInterface
    public void collectResultAsyn(Object msg, CompletionHandler<String> handler) {

        JsonParser parser = new JsonParser();
        JsonElement element = parser.parse((String) msg);
        if (element.isJsonObject()) {
            JsonObject jsonElement = (JsonObject) element;
            JsonObject dataElement = jsonElement.get("data").getAsJsonObject();
            int type = jsonElement.get("type").getAsInt();
            String code = dataElement.get("code").getAsString();

            if (1 == type) {
                if (ConstantsUtils.STATUS_SUCCESS_1000.equals(code)) {
                    ToastTools.showToast("收藏成功");
                } else if (ConstantsUtils.STATUS_SUCCESS_1008.equals(code)) {
                    ToastTools.showToast("已经收藏此商品");
                } else {
                    ToastTools.showToast("收藏失败");
                }
            } else if (2 == type) {
                if (ConstantsUtils.STATUS_SUCCESS_0000.equals(code)) {
                    ToastTools.showToast("取消收藏成功");
                } else if (ConstantsUtils.STATUS_SUCCESS_1008.equals(code)) {
                    ToastTools.showToast("已取消收藏");
                } else {
                    ToastTools.showToast("取消收藏失败");
                }
            }
        }
        handler.complete(msg.toString());
    }


    //报名咨询
    @JavascriptInterface
    public void consultAsyn(Object msg, CompletionHandler<String> handler) {

        startActivity(new Intent(this, PeiXunBaoMingActivity.class));
        handler.complete(msg + " [ asyn call]");
    }


    //H5定位
    @JavascriptInterface
    public void locationAsyn(Object msg, CompletionHandler<String> handler) {
//        Toast toast = Toast.makeText(DetailProductActivity.this, msg + "", Toast.LENGTH_SHORT);
//        toast.setGravity(Gravity.CENTER, 0, 0);
//        toast.show();
        if (msg != null) {
            if ("1".equals(msg)) {
                underlineAnimation22(shangpin);

            } else if ("3".equals(msg)) {
                underlineAnimation22(pingjia);

            } else if ("2".equals(msg)) {
                underlineAnimation22(xiangqing);

            } else if ("4".equals(msg)) {
                underlineAnimation22(tuijian);

            }
        }

        handler.complete(msg + " [ asyn call]");
    }

    //定位
    @OnClick({R.id.shangpin, R.id.pingjia, R.id.xiangqing, R.id.tuijian})
    public void onPosition(View view) {

        isClickTab = true;

        int viewId = view.getId();
        String currentPost = "1";
        switch (viewId) {
            case R.id.shangpin:
                currentPost = "1";
                break;
            case R.id.pingjia:
                currentPost = "2";


                break;
            case R.id.xiangqing:
                currentPost = "3";
                break;

            case R.id.tuijian:
                currentPost = "4";
                break;
        }


        webView.callHandler("pagePostion", new Object[]{currentPost}, new OnReturnValue<String>() {
            @Override
            public void onValue(String retValue) {

            }
        });
    }


    public void underlineAnimation22(final View view) {

        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                float endX = view.getX();
                Animation animation = new TranslateAnimation(startX, endX, 0, 0);
                animation.setFillAfter(true);
                animation.setDuration(250);
                // 给图片添加动画
                img_underline.startAnimation(animation);
                startX = view.getX();
            }
        });
    }

    //是否是真实商品
    @JavascriptInterface
    public void isRealAsyn(Object msg, CompletionHandler<String> handler) {

//        handler.complete("android");
        handler.complete("ios");
    }


    @OnClick({R.id.shangpin, R.id.pingjia, R.id.xiangqing, R.id.tuijian})
    public void underlineAnimation(View view) {

        float endX = view.getX();
        Animation animation = new TranslateAnimation(startX, endX, 0, 0);
        animation.setFillAfter(true);
        animation.setDuration(250);
        // 给图片添加动画
        img_underline.startAnimation(animation);
        startX = view.getX();
    }


    @Override
    protected void addListener() {

    }


    @OnClick({R.id.tv_share, R.id.tv_share_bottom})
    public void onShare() {
        if (DateUtils.isFastDoubleClick()) return;


        if (dialogShare == null) {
            dialogShare = new DialogShare(DetailProductActivity.this, DetailProductActivity.this);
        }


        webView.callHandler("getGoodsNameAndImage", new OnReturnValue<Object>() {
            @Override
            public void onValue(Object retValue) {
                Logger.i("-----------------" + retValue.toString());
                JsonParser parser = new JsonParser();
                JsonElement element = parser.parse((String) retValue);
                if (element.isJsonObject()) {
                    JsonObject jsonElement = (JsonObject) element;
                    String goodName = jsonElement.get("goodName").getAsString();
                    String goodImage = jsonElement.get("goodImage").getAsString();

                    String shareUrl = AppUtils.BASE_URL_H5 + "good/" + skuIdStr + ".html";
                    dialogShare.showDialog("我在融融上发现了一份好的资料，想邀分享给你", goodName, shareUrl, goodImage);

//                    generateLinkUrl(urlString, goodName,goodImage);
                }
            }
        });

    }


    public void generateLinkUrl(String articleUrl, String mTitleStr, String goodImage) {

        String tempUrl = urlString;

        //深度链接属性设置
        LinkProperties properties = new LinkProperties();
        //渠道
        properties.setChannel(DeviceUtils.getAppMetaData(this, ConstantsUtils.UMENG_CHANNEL));
        //功能
        properties.setFeature("Share");
        properties.setLMLink("推广活动");
        //标签
        properties.addTag("下载");
        //阶段
        properties.setStage("Live");
        //设置该h5_url目的是为了iOS点击右上角lkme.cc时跳转的地址，一般设置为当前分享页面的地址
//                           H5_URL + url_path其实就是就是分享的链接，不要被这个所误导
        properties.setH5Url(articleUrl);
        //自定义参数,用于在深度链接跳转后获取该数据
        properties.addControlParameter(ConstantsUtils.SHARE_USER_ID, SharedPreferencesUtil.getLoginToken());
        properties.addControlParameter(ConstantsUtils.SHARE_ID, "12312");
        properties.addControlParameter(ConstantsUtils.SHARE_TYPE, "4");

        LMUniversalObject universalObject = new LMUniversalObject();
        universalObject.setTitle(mTitleStr);
        universalObject.generateShortUrl(DetailProductActivity.this, properties, new LMLinkCreateListener() {
            @Override
            public void onLinkCreate(String tempUrl, LMError lmError) {
//                if (!TextUtils.isEmpty(articleUrl) && articleUrl.contains(ConstantsUtils.TYPE_CONTROL_SHARE_DOT) && articleUrl.contains("?")) {
//                    shareUtils.setUrlDefaultShare(articleUrl.split("\\?")[0] + "?linkedme=" + tempUrl, mTitleStr, articleThumb, activityDescreption);
//                    shareUtils.showShareBoard();

                     tempUrl = urlString + "?linkedme=" + tempUrl;

                    dialogShare.showDialog("我在融融上发现了一份好的资料，想邀分享给你", mTitleStr, tempUrl, goodImage);
//                }
            }
        });


    }


    float currentAlph = 0;

    @Override
    public void onScrollchange(int y, int direction) {


        Logger.i("---------------y--|" + y + "------" + direction);
        if (y < 100) {
            currentAlph = y * 1.0f / 100;
            rl_top.setAlpha(currentAlph);
//            Logger.i("----------------iii----" + currentAlph);
//            rl_top.getBackground().setAlpha((int)(currentAlph * 255));
            if (direction == 1) {

            } else {
                rl_root_bottom.setAlpha(1 - currentAlph);
            }
        } else {
            rl_top.setAlpha(1.0f);
            rl_top.setVisibility(View.VISIBLE);
        }


//        if (y > 50) {
//
//            // 隐藏title
//            if (!ishade&&(direction==1) && !isClickTab) {
//                AnimationSet animationSet = new AnimationSet(true);
//				/*
//				 * 　float fromXDelta:这个参数表示动画开始的点离当前View X坐标上的差值；
//　　                                         float toXDelta, 这个参数表示动画结束的点离当前View X坐标上的差值；
//　　                                       float fromYDelta, 这个参数表示动画开始的点离当前View Y坐标上的差值；
//　　                               float toYDelta)这个参数表示动画开始的点离当前View Y坐标上的差值；*/
////                TranslateAnimation translateAnimation = new TranslateAnimation(
////                        Animation.RELATIVE_TO_SELF, 0f,
////                        Animation.RELATIVE_TO_SELF, 0f,
////                        Animation.RELATIVE_TO_SELF, 0f,
////                        Animation.RELATIVE_TO_SELF, -1f);
//
////                translateAnimation.setDuration(AnimationDuration);
//
//                AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f,0);
//                alphaAnimation.setDuration(AnimationDuration);
//                alphaAnimation.setFillAfter(true);
////                animationSet.addAnimation(translateAnimation);
//                animationSet.addAnimation(alphaAnimation);
//                rl_top.startAnimation(animationSet);
//                rl_top.setVisibility(View.GONE);
//                ishade = true;
//            }
//            if (ishade&&(direction==0)) {
//                // 显示title
//                AnimationSet animationSet = new AnimationSet(true);
//
////                TranslateAnimation translateAnimation = new TranslateAnimation(
////                        Animation.RELATIVE_TO_SELF, 0f,
////                        Animation.RELATIVE_TO_SELF, 0f,
////                        Animation.RELATIVE_TO_SELF, -1f,
////                        Animation.RELATIVE_TO_SELF, 0f);
//
//                AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1.0f);
//                alphaAnimation.setDuration(AnimationDuration);
//                alphaAnimation.setFillAfter(true);
////                translateAnimation.setDuration(AnimationDuration);
////                animationSet.addAnimation(translateAnimation);
//                animationSet.addAnimation(alphaAnimation);
//                rl_top.startAnimation(animationSet);
//                // 显示title
//                rl_top.setVisibility(View.VISIBLE);
//                ishade = false;
//            }
//
//        } else {
//            if (ishade&&(direction==0)) {
//                // 显示title
//                AnimationSet animationSet = new AnimationSet(true);
//
////                TranslateAnimation translateAnimation = new TranslateAnimation(
////                        Animation.RELATIVE_TO_SELF, 0f,
////                        Animation.RELATIVE_TO_SELF, 0f,
////                        Animation.RELATIVE_TO_SELF, -1f,
////                        Animation.RELATIVE_TO_SELF, 0f);
////
////                translateAnimation.setDuration(AnimationDuration);
//
//                AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1.0f);
//                alphaAnimation.setDuration(AnimationDuration);
//                alphaAnimation.setFillAfter(true);
////                translateAnimation.setDuration(AnimationDuration);
//                animationSet.addAnimation(alphaAnimation);
////                animationSet.addAnimation(translateAnimation);
//                rl_top.startAnimation(animationSet);
//                // 显示title
//                rl_top.setVisibility(View.VISIBLE);
//                ishade = false;
//            }
//        }

        isClickTab = false;

    }


    @OnClick({R.id.img_back, R.id.img_back_bottom})
    public void onBack() {
        if (DateUtils.isFastDoubleClick()) return;
        onBackPressed();
    }

    @OnClick({R.id.tv_ok, R.id.tv_ok_bottom})
    public void OKClick() {
        if (DateUtils.isFastDoubleClick()) return;
        showPopup(DetailProductActivity.this, rl_top);
    }


    @Override
    public void onBackPressed() {
        Intent intent = new Intent();
        intent.putExtra(TYPE_ADDCARTFLAG, addCartFlag);
        setResult(100, intent);
        super.onBackPressed();
    }


    public static Intent getIntent(Context context, String skuId) {
        Intent intent = new Intent(context, DetailProductActivity.class);
        intent.putExtra(ARG_SKUID, skuId);
        return intent;
    }

    public static Intent getIntent(Context context, String skuId, int Type) {
        Intent intent = new Intent(context, DetailProductActivity.class);
        intent.putExtra(ARG_SKUID, skuId);
        intent.putExtra(TYPE, Type);
        return intent;
    }

    @Override
    public void onSwipeBackLayoutExecuted() {
        Intent intent = new Intent();
        intent.putExtra(TYPE_ADDCARTFLAG, addCartFlag);
        setResult(100, intent);

        super.onSwipeBackLayoutExecuted();
    }

    @Override
    public void shareSuccess() {

    }

    @Override
    public void shareFailed() {

    }

    @Override
    public void shareCancel() {

    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(dialogShare!=null){
            dialogShare.initActivityResultSsoHandler(requestCode,resultCode,data);
        }
    }
}
